<?php

namespace app\common\model\config;

use app\common\model\BaseModel;

class AppConfig extends BaseModel
{
    protected $name = 'system';
    protected $pk = 'id';

    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

    protected $type = [
        'create_time' => 'timestamp',
        'update_time' => 'timestamp',
    ];

    /**
     * 获取配置信息
     * @param string $name 配置名称
     * @return mixed
     */
    public function getConfig(string $name)
    {
        $config = $this->where('name', $name)->find();
        if (!$config) {
            return '';
        }

        $value = $config['value'];
        if ($config['type'] === 'app') {
            $value = json_decode($value, true);
        }

        return $value;
    }
}